This is just an example of stuff
1 import db_constraints; 2 @CheckConstraint!(a => a.firstName != a.lastName, "chk_First_Last") 3 class Person 4 { 5 private: 6 Nullable!int _id; 7 string _firstName; 8 string _lastName; 9 string _email; 10 public: 11 @PrimaryKeyColumn @NotNull 12 @property Nullable!int id() const nothrow pure @safe @nogc 13 { 14 return _id; 15 } 16 @UniqueConstraintColumn!("uc_Person") 17 @property string firstName() const nothrow pure @safe @nogc 18 { 19 return _firstName; 20 } 21 @property void firstName(string value) 22 { 23 setter(_firstName, value); 24 } 25 @UniqueConstraintColumn!("uc_PersonEmail") 26 @property string email() const nothrow pure @safe @nogc 27 { 28 return _email; 29 } 30 @property void email(string value) 31 { 32 setter(_email, value); 33 } 34 @UniqueConstraintColumn!("uc_Person") 35 @property string lastName() const nothrow pure @safe @nogc 36 { 37 return _lastName; 38 } 39 40 this(string firstName_, string lastName_, string email_) 41 { 42 static int i = 1; 43 this._id = i; 44 this._firstName = firstName_; 45 this._lastName = lastName_; 46 this._email = email_; 47 ++i; 48 initializeKeyedItem(); 49 } 50 Person dup() 51 { 52 return new Person(this._firstName, this._lastName, this._email); 53 } 54 mixin KeyedItem!(UniqueConstraintColumn!("uc_PersonEmail")); 55 } 56 57 { 58 alias People = BaseKeyedCollection!(Person); 59 auto people = new People([new Person("Valid", "Person", "vp@test.com"), new Person("Second", "Sup", "s@e.org")]); 60 assert(people.contains("s@e.org")); 61 //assert(!people.contains(null)); 62 people["s@e.org"].email = "hello@all"; 63 assert(people.contains("hello@all")); 64 people["hello@all"].email = null; 65 assert(!people.contains("s@e.org")); 66 assert(!people.contains("hello@all")); 67 auto i = Person.uc_PersonEmail(); 68 i.email = null; 69 assert(people.contains(i)); 70 } 71 { 72 import std.exception : assertThrown; 73 assertThrown!CheckConstraintException(new Person("Name", "Name", "Name@org")); 74 }
Really important class